package at.irian.jsfatwork.broker.web.model;

import at.irian.jsfatwork.broker.domain.client.Client;
import at.irian.jsfatwork.broker.domain.client.ClientRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author Thomas Spiegl
 */
@Component
@Scope("session")
public class ClientBean {

    @Autowired
    private AuthorizationBean authorizationBean;

    @Autowired
    private ClientRepository clientRepository;

    private Client client;

    // ----------------------------- Bindings

    public void setClient(Client client) {
        this.client = client;
    }

    public Client getClient() {
        if (client == null) {
            if (authorizationBean.isUserClientOnly()) {
                client = authorizationBean.getAuthenticatedClient();
            }
        }
        return client;
    }

    // ----------------------------- Actions

    // ----------------------------- Misc

}
